package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RepairOrders;
import com.ruoyi.system.service.IRepairOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备维修工单记录Controller
 *
 * @author ruoyi
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/system/orders")
public class RepairOrdersController extends BaseController {
    @Autowired
    private IRepairOrdersService repairOrdersService;

    /**
     * 查询设备维修工单记录列表
     */
    //@PreAuthorize("@ss.hasPermi('system:orders:list')")
    @GetMapping("/list")
    public TableDataInfo list(RepairOrders repairOrders) {
        startPage();
        List<RepairOrders> list = repairOrdersService.selectRepairOrdersList(repairOrders);
        return getDataTable(list);
    }

    /**
     * 查询设备维修工单记录列表
     */
    //@PreAuthorize("@ss.hasPermi('system:orders:list')")
    @GetMapping("/xialaxuan")
    public AjaxResult xialaxuan(RepairOrders repairOrders) {
        List<RepairOrders> list = repairOrdersService.selectRepairOrdersList(repairOrders);
        return AjaxResult.success(list);
    }

    /**
     * 导出设备维修工单记录列表
     */
    //@PreAuthorize("@ss.hasPermi('system:orders:export')")
    //@Log(title= "设备维修工单记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RepairOrders repairOrders) {
        List<RepairOrders> list = repairOrdersService.selectRepairOrdersList(repairOrders);
        ExcelUtil<RepairOrders> util = new ExcelUtil<RepairOrders>(RepairOrders.class);
        util.exportExcel(response, list, "设备维修工单记录数据");
    }

    /**
     * 获取设备维修工单记录详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:orders:query')")
    @GetMapping(value = "/{repairOrderCode}")
    public AjaxResult getInfo(@PathVariable("repairOrderCode") String repairOrderCode) {
        return success(repairOrdersService.selectRepairOrdersByRepairOrderCode(repairOrderCode));
    }

    /**
     * 新增设备维修工单记录
     */
    //@PreAuthorize("@ss.hasPermi('system:orders:add')")
    //@Log(title= "设备维修工单记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RepairOrders repairOrders) {
        return toAjax(repairOrdersService.insertRepairOrders(repairOrders));
    }

    /**
     * 修改设备维修工单记录
     */
    //@PreAuthorize("@ss.hasPermi('system:orders:edit')")
    //@Log(title= "设备维修工单记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RepairOrders repairOrders) {
        return toAjax(repairOrdersService.updateRepairOrders(repairOrders));
    }

    /**
     * 删除设备维修工单记录
     */
    //@PreAuthorize("@ss.hasPermi('system:orders:remove')")
    //@Log(title= "设备维修工单记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{repairOrderCodes}")
    public AjaxResult remove(@PathVariable String[] repairOrderCodes) {
        return toAjax(repairOrdersService.deleteRepairOrdersByRepairOrderCodes(repairOrderCodes));
    }
}
